package com.acwing.lc.part1;

import java.io.*;

/**
 * @author rkc
 * @date 2022/9/5 14:37
 */
public class LC5最长回文子串_枚举 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        writer.write(longestPalindrome(reader.readLine()));
        writer.flush();
    }

    public static String longestPalindrome(String s) {
        String ans = "";
        for (int i = 0; i < s.length(); i++) {
            int l = i - 1, r = i + 1;
            while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) {
                l--;
                r++;
            }
            if (r - l - 1 > ans.length()) ans = s.substring(l + 1, r);
            l = i;
            r = i + 1;
            while (l >= 0 && r < s.length() && s.charAt(l) == s.charAt(r)) {
                l--;
                r++;
            }
            if (r - l - 1 > ans.length()) ans = s.substring(l + 1, r);
        }
        return ans;
    }
}
